﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;

using DotNetUI.Controls;

using Microsoft.Extensions.DependencyInjection;

using Xc.Views.Booster.Services;
using Xc.Views.Booster.Views;

namespace Microsoft.Extensions.DependencyInjection
{
    /// <summary>
    /// 应用程序配置服务
    /// </summary>
    public static class ApplicationExtension
    {
        /// <summary>
        /// 获取应用程序启动器
        /// </summary>
        /// <typeparam name="TAppSetting"></typeparam>
        /// <param name="serviceDescriptors"></param>
        /// <returns></returns>
        public static IServiceCollection AddSettingService<TAppSetting>(this IServiceCollection serviceDescriptors) where TAppSetting : class
        {
            serviceDescriptors.AddTransient<IAppSettingService, AppSettingService<TAppSetting>>();
            serviceDescriptors.AddTransient<SettingView>();
            return serviceDescriptors;
        }
        /// <summary>
        /// 获取应用程序配置服务
        /// </summary>
        /// <param name="serviceProvider"></param>
        /// <returns></returns>
        public static IAppSettingService GetAppSettingService(this IServiceProvider serviceProvider)
        {
            return serviceProvider.GetService<IAppSettingService>();
        }
        /// <summary>
        /// 获取Dotnet窗口视图服务
        /// </summary>
        /// <typeparam name="TService"></typeparam>
        /// <param name="serviceProvider"></param>
        /// <returns></returns>
        public static DotNetWindow GetDotNetWindowService<TService>(this IServiceProvider serviceProvider)
        {
            return serviceProvider.GetWindowService<DotNetWindow,TService>();
        }
        /// <summary>
        /// 获取Window视图服务
        /// </summary>
        /// <typeparam name="TWindow"></typeparam>
        /// <typeparam name="TService"></typeparam>
        /// <param name="serviceProvider"></param>
        /// <returns></returns>
        public static TWindow GetWindowService<TWindow, TService>(this IServiceProvider serviceProvider) where TWindow : Window,new()
        {
           var svc=  serviceProvider.GetService<TService>();
            TWindow window = new TWindow();
            window.Content = svc;
            return window;
        }
    }
}
